<#assign ctx=springMacroRequestContext.contextPath />
<#include "/macro/publicMacro.ftl">
<#import "/macro/pagination.ftl" as Pagination>
<#import "/macro/FormItem.ftl" as Form>

<@header title="权限编辑">
</@header>

<@body>
    <h2 class="module-title"><#if authority.id??>编辑权限</#if><#if !(authority.id??)>添加权限</#if></h2>

    <div class="alert alert-primary" role="alert">
        <#--<button class="btn btn-info" onclick="javascript: history.back(-1);return false;">返回</button>-->
        <a class="btn btn-info btn-sm" href="${ctx}/authority/list" role="button" aria-pressed="true">返回</a>
    </div>

    <#if error??>
    <div class="alert alert-warning" role="alert">
        <h3>${error}</h3>
    </div>
    </#if>

    <form class="form-horizontal" id="authorityForm" action="${ctx}/authority/save" method="post">
        <input type="hidden" name="id" id="authorityId" value="${authority.id}"/>
        <@Form.FormItem name="name" label="权限名称">
            <input type="text" class="form-control" name="name" id="name" aria-describedby="权限名称" value="${authority.name}">
        </@Form.FormItem>
        <@Form.FormItem name="description" label="描述">
            <input type="text" class="form-control" name="description" id="description" aria-describedby="描述" value="${authority.description}">
        </@Form.FormItem>
        <@Form.FormItem name="status" label="状态">
            <select class="form-control" name="status" id="status">
                <#list statusValues as status>
                    <option value="${status}" <#if status == authority.status>selected</#if>>${status.desc}</option>
                </#list>
            </select>
        </@Form.FormItem>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="submit" class="btn btn-primary">Submit</button>
            </div>
        </div>
    </form>
</@body>

<@footer>
    <script src="${ctx}/resource/common/js/jquery.validate.min.js"></script>
    <script src="${ctx}/resource/common/js/validate.message.cn.js"></script>
    <script src="${ctx}/resource/common/js/additional-methods.min.js"></script>


    <script type="text/javascript">
        $().ready(function () {
            $("#authorityForm").validate({
                rules: {
                    id: {
                        required: true,
                        digits: true
                    },
                    name: {
                        required: true,
                        remote: {
                            url: "${ctx}/authority/checkName/json",
                            type: "get",
                            data: {
                                id: function () {
                                    return $("#authorityId").val();
                                },
                                moduleId: function() {
                                    return $("#module-id").val();
                                }
                            }
                        }
                    },
                    description: {
                        maxlength: 128
                    },
                    status: "required"
                },
                messages: {
                    name: {
                        required: '权限名称不能为空',
                        remote: '权限名称重复'
                    }
                }
            });
        });
    </script>
</@footer>